<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>第9章：数组方法 | MarkDown的使用</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../JavaScript/JavaScript_10.html" />
    
    
    <link rel="prev" href="../JavaScript/JavaScript_8.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.9"
        data-chapter-title="第9章：数组方法"
        data-filepath="JavaScript/JavaScript_9.md"
        data-basepath=".."
        data-revision="Sat Nov 10 2018 16:39:50 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="HTML/html_int.html">
            
                
                    <a href="../HTML/html_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        HTML5简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="HTML/gitbook_use.html">
            
                
                    <a href="../HTML/gitbook_use.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        第0章：gitbook的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="HTML/lesson1.html">
            
                
                    <a href="../HTML/lesson1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        第1章：常用标签
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="HTML/lesson2.html">
            
                
                    <a href="../HTML/lesson2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第2章：列表与图片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="HTML/lesson3.html">
            
                
                    <a href="../HTML/lesson3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        第3章：表格与表单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="HTML/lesson4.html">
            
                
                    <a href="../HTML/lesson4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        第4章：实体字符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="HTML/lesson5.html">
            
                
                    <a href="../HTML/lesson5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        第5章：多媒体和iframe
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="CSS/css_int.html">
            
                
                    <a href="../CSS/css_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        CSS简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="CSS/css_1.html">
            
                
                    <a href="../CSS/css_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        第1章：引入css
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="CSS/css_2.html">
            
                
                    <a href="../CSS/css_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        第2章：选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="CSS/css_3.html">
            
                
                    <a href="../CSS/css_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        第3章：属性选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="CSS/css_4.html">
            
                
                    <a href="../CSS/css_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        第4章：伪类选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="CSS/css_5.html">
            
                
                    <a href="../CSS/css_5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        第5章：盒子模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="CSS/css_6.html">
            
                
                    <a href="../CSS/css_6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        第6章：伪对象选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="CSS/css_7.html">
            
                
                    <a href="../CSS/css_7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        第7章：font字体与边框
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="CSS/css_8.html">
            
                
                    <a href="../CSS/css_8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        第8章：行高
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="CSS/css_9.html">
            
                
                    <a href="../CSS/css_9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        第9章：文字与背景
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="CSS/css_10.html">
            
                
                    <a href="../CSS/css_10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        第10章：浮动
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="CSS/css_11.html">
            
                
                    <a href="../CSS/css_11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        第11章：定位与渐变
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="CSS/css_12.html">
            
                
                    <a href="../CSS/css_12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.</b>
                        
                        第12章：css过渡与变形
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="CSS/css_13.html">
            
                
                    <a href="../CSS/css_13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.13.</b>
                        
                        第13章：css动画
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="CSS/css_14.html">
            
                
                    <a href="../CSS/css_14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.</b>
                        
                        第14章：css滤镜
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="CSS/css_15.html">
            
                
                    <a href="../CSS/css_15.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.</b>
                        
                        第15章：swiper与地图插件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.16" data-path="CSS/css_16.html">
            
                
                    <a href="../CSS/css_16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.16.</b>
                        
                        第16章：移动端rem布局
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.17" data-path="CSS/css_17.html">
            
                
                    <a href="../CSS/css_17.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.17.</b>
                        
                        第17章：伸缩盒子
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="SASS/sass_int.html">
            
                
                    <a href="../SASS/sass_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        sass简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="SASS/sass_1.html">
            
                
                    <a href="../SASS/sass_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        第1章：sass安装与使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="SASS/sass_2.html">
            
                
                    <a href="../SASS/sass_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        第2章：sass语法入门
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="Bootstrap/Bootstrap_int.html">
            
                
                    <a href="../Bootstrap/Bootstrap_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Bootstrap简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="Bootstrap/Bootstrap_1.html">
            
                
                    <a href="../Bootstrap/Bootstrap_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        第1章：Bootstrap
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="JavaScript/JavaScript_int.html">
            
                
                    <a href="../JavaScript/JavaScript_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        JavaScript简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="JavaScript/JavaScript_1.html">
            
                
                    <a href="../JavaScript/JavaScript_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        第1章：JavaScript
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="JavaScript/JavaScript_2.html">
            
                
                    <a href="../JavaScript/JavaScript_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        第2章：变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="JavaScript/JavaScript_3.html">
            
                
                    <a href="../JavaScript/JavaScript_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        第3章：Number
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="JavaScript/JavaScript_4.html">
            
                
                    <a href="../JavaScript/JavaScript_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        第4章：数据类型判断
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="JavaScript/JavaScript_5.html">
            
                
                    <a href="../JavaScript/JavaScript_5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        第5章：运算符与字符串
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="JavaScript/JavaScript_6.html">
            
                
                    <a href="../JavaScript/JavaScript_6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        第6章：循环与流程控制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="JavaScript/JavaScript_7.html">
            
                
                    <a href="../JavaScript/JavaScript_7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        第7章：函数与作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="JavaScript/JavaScript_8.html">
            
                
                    <a href="../JavaScript/JavaScript_8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        第8章：String方法
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.9" data-path="JavaScript/JavaScript_9.html">
            
                
                    <a href="../JavaScript/JavaScript_9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        第9章：数组方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="JavaScript/JavaScript_10.html">
            
                
                    <a href="../JavaScript/JavaScript_10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        第10章：定时器与排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.11" data-path="JavaScript/JavaScript_11.html">
            
                
                    <a href="../JavaScript/JavaScript_11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.11.</b>
                        
                        第11章：Date与Math
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.12" data-path="JavaScript/JavaScript_12.html">
            
                
                    <a href="../JavaScript/JavaScript_12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.12.</b>
                        
                        第12章：简单的DOM操作与垃圾回收
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.13" data-path="JavaScript/JavaScript_13.html">
            
                
                    <a href="../JavaScript/JavaScript_13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.13.</b>
                        
                        第13章：DOM操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.14" data-path="JavaScript/JavaScript_14.html">
            
                
                    <a href="../JavaScript/JavaScript_14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.14.</b>
                        
                        第14章：DOM修改样式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.15" data-path="JavaScript/JavaScript_15.html">
            
                
                    <a href="../JavaScript/JavaScript_15.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.15.</b>
                        
                        第15章：DOM常用标签属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.16" data-path="JavaScript/JavaScript_16.html">
            
                
                    <a href="../JavaScript/JavaScript_16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.16.</b>
                        
                        第16章：鼠标坐标与拖拽
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >MarkDown的使用</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;">&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;</h1>
<pre><code>            /**
             * &#x6570;&#x7EC4;&#xFF1A;&#x5F3A;&#x8C03;&#x987A;&#x5E8F;&#x7684;&#x6570;&#x636E;&#x96C6;&#x5408;
             *          &#x957F;&#x5EA6;&#x548C;&#x4E0B;&#x6807;&#x90FD;&#x662F;&#x7ECF;&#x5E38;&#x548C;&#x6570;&#x7EC4;&#x7ED3;&#x5408;&#x4F7F;&#x7528;
             *          &#x4E0B;&#x6807;&#x5176;&#x5B9E;&#x662F;&#x4E2A;&#x6BD4;&#x8F83;&#x7279;&#x6B8A;&#x7684;&#x5C5E;&#x6027;&#x540D;
             * */
            var arr1 = [1,&quot;string&quot;,{
                name : &quot;&#x5F20;&#x4E09;&quot;,
                age : 18,
            }];
            console.log(arr1.length,arr1[2].name)

            var obj = {name : &quot;&#x674E;&#x56DB;&quot;,age : 19}
            console.log(obj.name,obj[&quot;name&quot;])

            // &#x901A;&#x8FC7;Array&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x5B9E;&#x4F8B;
            var arr2 = new Array(1,2,3);
            console.log(arr2)

            var arr3 = [1,2,3,4,5];
            // &#x4E3B;&#x52A8;&#x8BBE;&#x7F6E;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#xFF0C;&#x6BD4;&#x539F;&#x6765;&#x5927;&#x65F6;&#xFF0C;&#x591A;&#x51FA;&#x7684;&#x662F;undefined&#xFF0C;&#x6BD4;&#x539F;&#x6765;&#x5C11;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x5220;&#x9664;&#x540E;&#x9762;&#x7684;&#x5143;&#x7D20;
            arr3.length = 2;                                
            console.log(&quot;arr3&#x7684;&#x957F;&#x5EA6;&quot;,arr3)
            arr3[5] = 5;                    // &#x8BBE;&#x7F6E;&#x540E;&#x7EED;&#x4E0B;&#x6807;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x589E;&#x52A0;&#x4E86;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;
            console.log(arr3)

            console.clear()                    // &#x6E05;&#x7A7A;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x51FA;&#x7684;&#x5143;&#x7D20;

            var arr4 = [];
            // &#x4F5C;&#x7528;&#x5728;&#x539F;&#x6570;&#x7EC4;&#x4E0A;&#xFF0C;&#x4ECE;&#x961F;&#x5C3E;&#x589E;&#x52A0;&#x65B0;&#x5143;&#x7D20;
            arr4.push(1,2,3);
            console.log(&quot;push&quot;,arr4)
            // &#x4F5C;&#x7528;&#x5728;&#x539F;&#x6570;&#x7EC4;&#x4E0A;&#xFF0C;&#x4ECE;&#x961F;&#x5C3E;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF08;&#x62EC;&#x53F7;&#x5185;&#x6CA1;&#x6709;&#x53C2;&#x6570;&#xFF09;
            arr4.pop();
            console.log(&quot;pop&quot;,arr4)
            // &#x4F5C;&#x7528;&#x5728;&#x539F;&#x6570;&#x7EC4;&#x4E0A;&#xFF0C;&#x4ECE;&#x961F;&#x5934;&#x589E;&#x52A0;&#x65B0;&#x5143;&#x7D20;
            arr4.unshift(-1,0);
            console.log(&quot;unshift&quot;,arr4)
            // &#x4F5C;&#x7528;&#x5728;&#x539F;&#x6570;&#x7EC4;&#x4E0A;&#xFF0C;&#x4ECE;&#x961F;&#x5934;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF08;&#x62EC;&#x53F7;&#x5185;&#x6CA1;&#x6709;&#x53C2;&#x6570;&#xFF09;
            arr4.shift();
            console.log(&quot;shift&quot;,arr4)
            // &#x5220;&#x9664;&#x961F;&#x5C3E;&#x7684;&#x4E24;&#x4E2A;
            console.log(arr4.length = arr4.length - 2)
            console.log(arr4)

            /**
             *     push&#x548C;unshift&#xFF08;&#x6DFB;&#x52A0;&#xFF09;&#x8FD4;&#x56DE;&#x66F4;&#x65B0;&#x540E;&#x7684;&#x957F;&#x5EA6;
             *     pop&#x548C;shift&#xFF08;&#x5220;&#x9664;&#xFF09;&#x8FD4;&#x56DE;&#x5220;&#x9664;&#x7684;&#x5143;&#x7D20;
             * */


            // &#x5C01;&#x88C5; &#x5220;&#x9664;&#x6570;&#x7EC4;&#x961F;&#x5C3E;&#x591A;&#x4E2A;&#x5143;&#x7D20;
            function popMore(arr,num){
                arr.length = arr.length - num;
                return arr;
            }
            console.log(popMore([1,2,3,4,5],2));



            var arr5 = [12,34];
            var arr6 = [56,78];
            // &#x62FC;&#x63A5;&#x591A;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;
            arr5 = arr5.concat(arr6,[90,100]);
            console.log(&quot;concat&quot;,arr5)


            /**
             *     splice(start,lenght,newElement) 
             *         start: &#x88AB;&#x66FF;&#x4EE3;&#x5143;&#x7D20;&#x7684;&#x5F00;&#x59CB;&#x4E0B;&#x6807;
             *         lenght&#xFF1A; &#x4ECE;start&#x5F00;&#x59CB;&#x6570;&#x7684;&#x957F;&#x5EA6;
             *         newElement&#xFF1A; &#x65B0;&#x66FF;&#x4EE3;&#x7684;&#x5143;&#x7D20;
             *     &#x66FF;&#x4EE3;&#xFF1A;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x90FD;&#x7ED9;&#xFF0C;&#x957F;&#x5EA6;&#x8BBE;&#x7F6E;1&#xFF0C;&#x66FF;&#x4EE3;&#x5355;&#x4E2A;&#x5143;&#x7D20;&#xFF1A;&#x957F;&#x5EA6;&#x5927;&#x4E8E;1&#xFF0C;&#x5355;&#x4E2A;&#x5143;&#x7D20;&#x66FF;&#x4EE3;&#x591A;&#x4E2A;&#x5143;&#x7D20;
             *     &#x5220;&#x9664;&#xFF1A;&#x53EA;&#x7ED9;&#x4E24;&#x4E2A;&#x53C2;&#x6570;
             *     &#x589E;&#x52A0;&#xFF1A;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x90FD;&#x7ED9;&#xFF0C;&#x957F;&#x5EA6;&#x8BBE;&#x7F6E;&#x4E3A;0
             *     &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x4EE5;&#x6570;&#x7EC4;&#x5F62;&#x5F0F;&#x8FD4;&#x56DE;&#x88AB;&#x5220;&#x9664;&#x5143;&#x7D20;
             * */  
            var arr7 = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;];
            console.log(arr7.splice(0,2,&quot;A&quot;,&quot;B&quot;,&quot;AB&quot;))        
            console.log(&quot;splice&quot;,arr7)


            // &#x622A;&#x53D6;&#x6570;&#x7EC4;&#xFF0C;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;
            var arr8 = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;];
            arr8 = arr8.slice(1,3);
            console.log(&quot;slice&quot;,arr8)

            // join &#x5C06;&#x6570;&#x7EC4;&#x4EE5;&#x67D0;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5;&#x5E76;&#x8F6C;&#x6362;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x9ED8;&#x8BA4;&#x9017;&#x53F7;&#x8FDE;&#x63A5;
            var str1 = &quot;get-element-by-id&quot;;
            var arr9 = str1.split(&quot;-&quot;);
            console.log(arr9.join(&quot;&quot;))

            // &#x53CD;&#x8F6C;&#x6570;&#x7EC4;
            var arr10 = [0,1,2].reverse();
            console.log(&quot;reverse&quot;,arr10)


            // sort &#x6392;&#x5E8F;        &#x5347;&#x5E8F;&#xFF1A;a-b    &#x964D;&#x5E8F;&#xFF1A;b-a
            var arr11 = [1,3,5,2,4];
            arr11.sort(function(a,b){
                return b - a;
            })
            console.log(&quot;sort&quot;,arr11)







            console.clear()


            // map &#x904D;&#x5386;&#x6570;&#x7EC4;&#x7684;&#x6BCF;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x5E76;&#x5904;&#x7406;&#x5143;&#x7D20;&#x7684;&#x503C;&#xFF0C;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;
            var arr12 = [1,2,3];
            arr12 = arr12.map(function(item,index,arr){
                return item*2;
            })
            console.log(&quot;map&quot;,arr12)

            // filter &#x7528;&#x4E8E;&#x8FC7;&#x6EE4;&#x5185;&#x5BB9;&#xFF0C;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x8FD4;&#x56DE;true&#xFF0C;&#x6DFB;&#x52A0;&#x5230;&#x65B0;&#x6570;&#x7EC4;&#xFF1B;&#x8FD4;&#x56DE;false&#xFF0C;&#x5219;&#x4E0D;&#x6DFB;&#x52A0;
            var arr13 = [1,2,3,4,5,6];
            arr13 = arr13.filter(function(item,index){
                if( item % 2 != 0 ){
                    // &#x5947;&#x6570;
                    return false;
                }
                return true;
            })
            console.log(&quot;filter&quot;,arr13)

            // forEach &#x904D;&#x5386;&#x6570;&#x7EC4;&#xFF0C;&#x8FD4;&#x56DE;undefined
            var arr14 = [1,2,3,4,5,6];
            arr14.forEach(function(item,index){
                console.log(item)
            })
            console.log(&quot;forEach&quot;,arr14)

            // indexOf(&#x641C;&#x7D22;&#x7684;&#x5143;&#x7D20;)    &#x6CE8;&#x610F;&#x7C7B;&#x578B;&#x76F8;&#x540C;&#x624D;&#x80FD;&#x5339;&#x914D;&#x4F4D;&#x7F6E;
            console.log(&quot;indexOf&quot;,arr14.indexOf(6))
            console.log(&quot;lastIndexOf&quot;,arr14.lastIndexOf(4))






            // &#x7EC3;&#x4E60;&#xFF1A;&#x968F;&#x673A;5&#x4E2A;&#x4E0D;&#x76F8;&#x540C;&#x7684;&#x6570;&#x5B57;&#xFF0C;&#x6570;&#x5B57;&#x8303;&#x56F4;&#x5728;[1~10]&#xFF0C;&#x5E76;&#x4E14;&#x6DFB;&#x52A0;&#x5230;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x4E2D;
            // &#x968F;&#x673A;&#x6570;Math.random() &#x5411;&#x4E0A;&#x53D6;&#x6574;&#xFF1A;Math.ceil()
            var arr15 = [];
            for(var i = 0; i &lt; 5;){
                console.count();                // &#x63A7;&#x5236;&#x53F0;&#x8BA1;&#x6570;
                var num2 = Math.random()*10;    // &#x968F;&#x673A;&#x6570;(0~10)
                num2 = Math.ceil(num2);            // &#x968F;&#x673A;&#x6570;[1~10]
                if(arr15.length == 0 || arr15.indexOf(num2)==-1){
                    // length &#x4E3A;0 &#xFF0C;&#x5373;&#x6570;&#x7EC4;&#x4E3A;&#x7A7A;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x68C0;&#x67E5;&#x662F;&#x5426;&#x91CD;&#x590D;&#xFF08;&#x7B2C;&#x4E00;&#x6B21;&#x6DFB;&#x52A0;&#xFF09;
                    // indexOf() &#x7ED3;&#x679C;&#x4E3A;-1&#xFF0C;&#x5373;&#x6CA1;&#x6709;&#x91CD;&#x590D;&#x7684;&#x5143;&#x7D20;&#xFF08;&#x9664;&#x7B2C;&#x4E00;&#x6B21;&#x5916;&#xFF09;
                    arr15.push(num2);
                    i++;    // &#x53EA;&#x6709;&#x6210;&#x529F;&#x6DFB;&#x52A0;&#x7684;&#x6B21;&#x6570;&#x624D;&#x7B97;&#x4E0B;&#x4E00;&#x6B21;
                }
            }
            console.log(arr15)
</code></pre>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../JavaScript/JavaScript_8.html" class="navigation navigation-prev " aria-label="Previous page: 第8章：String方法"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../JavaScript/JavaScript_10.html" class="navigation navigation-next " aria-label="Next page: 第10章：定时器与排序"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
